package com.xzlf.timer;

import com.alibaba.fastjson.JSON;
import lombok.SneakyThrows;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

public class MyTimer {
    public static void main(String[] args) {
        TimerTask timerTask = new TimerTask() {
            @SneakyThrows
            @Override
            public void run() {
                TimeUnit.SECONDS.sleep(5);
                System.out.println("timertask 1 -->" + JSON.toJSONStringWithDateFormat(new Date(), "yyyy-MM-dd HH:mm:ss"));
            }
        };
        TimerTask timerTask2 = new TimerTask() {
            @Override
            public void run() {
                System.out.println("timertask 2 -->" + JSON.toJSONStringWithDateFormat(new Date(), "yyyy-MM-dd HH:mm:ss"));
            }
        };
        Timer timer = new Timer();
        timer.schedule(timerTask, 0, 3000L);
        timer.schedule(timerTask2, 0, 3000L);
    }
}
